import { _decorator, Component, Node, misc, Label, Sprite, find } from 'cc';
import { Constant } from '../Common/Constant';
import { ResourceUtil } from '../Common/ResourceUtil';
import { UIManager } from '../Manager/UIManager';
const { ccclass, property } = _decorator;

@ccclass('TipPanel')
export class TipPanel extends Component {

    titleLb: Label = null!;

    acceptButtonNd: Node = null!;
    acceptButtonLb: Label = null!;
    cancelButtonNd: Node = null!;
    cancelButtonLb: Label = null!;

    descLb: Label = null!;

    sprite: Sprite = null!;

    func: Function = null!;

    onLoad() {
        this.titleLb = find("Panel/TitleLb", this.node).getComponent(Label);

        this.acceptButtonNd = find("Panel/Buttons/AcceptButton", this.node);
        this.acceptButtonLb = find("Panel/Buttons/AcceptButton/Label", this.node).getComponent(Label);
        this.cancelButtonNd = find("Panel/Buttons/CancelButton", this.node);
        this.cancelButtonLb = find("Panel/Buttons/CancelButton/Label", this.node).getComponent(Label);

        this.descLb = find("Panel/DescLb", this.node).getComponent(Label);

        this.sprite = find("Panel/Sprite", this.node).getComponent(Sprite);
    }

    Show(title: string, spritePath: string, descLb: string, acceptButtonLb: string, cancelButtonLb: string, isOneButton: boolean, callback: Function) {
        this.func = null;
        this.func = callback;

        ResourceUtil.loadSpriteFrameRes(spritePath).then((spriteFrame: any) => {
            this.sprite.spriteFrame = spriteFrame;
        });

        this.titleLb.string = title;
        this.descLb.string = descLb;
        this.acceptButtonLb.string = acceptButtonLb;
        this.cancelButtonLb.string = cancelButtonLb;
        this.acceptButtonNd.active = !isOneButton;
    }

    OnAcceptButtonClick() {
        if (this.func) {
            this.func();
        }
    }

    OnCancelButtonClick() {
        UIManager.Instance.HidePanel(Constant.Panel.TipPanel);
    }

}


